Test Series - Data Structure

Test Number 35/115

Q: Both Dynamic array and Dynamically memory allocated array are same.
A.  True
B. False
C. ....
D. ....
Solution: Physical size of a Dynamic array is fixed with a larger value. Dynamically memory allocated arrays are arrays whose memory is allocated at run time rather than at compile time. Dynamically memory allocated arrays don’t have physical size at the backend. Thus, Dynamic arrays and Dynamically memory allocated arrays are different.
Q: In which of the following cases dynamic arrays are not preferred?
A. If the size of the array is unknown
B. If the size of the array changes after few iterations
C. If the memory reallocation takes more time i.e. expensive
D. If the array holds less number of elements
Solution: Dynamic arrays are preferred when the size of the array is unknown during memory allocation or the size changes after few iterations or the memory reallocation is expensive. If array holds less number of elements, the physical size is reduced and reduction takes more time. In that case, we can use normal arrays instead of dynamic arrays.
Q: The growth factor of ArrayList in Java is _______
A. 1
B. 1.5
C. 2
D. 0
Solution: The growth factor of dynamic arrays (Array List) in Java is 3/2.
The new array capacity is calculated as new_array_size = (old_array_size*3)/2+1.
Q: In special case, the time complexity of inserting/deleting elements at the end of dynamic array is __________
A. O (n)
B. O (n1/2)
C. O (log n)
D. O (1)
Solution: In general, the time complexity of inserting or deleting elements at the end of dynamic array is O (1). Elements are added at reserved space of dynamic array. If this reserved space is exceeded, then the physical size of the dynamic array is reallocated and every element is copied from original array. This will take O(n) time to add new element at the end of the array.
Q: Which of the following arrays are used in the implementation of list data type in python?
A. Bit array
B. Dynamic arrays
C. Sparse arrays
D. Parallel arrays
Solution: Dynamic arrays are used in the implementation of list data type in python. Sparse arrays are used in the implementation of sparse matrix in Numpy module. All bit array operations are implemented in bitarray module.
Q: What are parallel arrays?
A. Arrays of the same size
B. Arrays allocated one after the other
C. Arrays of the same number of elements
D. Arrays allocated dynamically
Solution: Different arrays can be of different data types but should contain same number of elements. Elements at corresponding index belong to a record.
Q: Which of the following is a disadvantage of parallel array over the traditional arrays?
A.  When a language does not support records, parallel arrays can be used
B.  Increased locality of reference
C. Ideal cache behaviour
D. Insertion and Deletion becomes tedious
Solution: Insertion and deletion of elements require to move every element from their initial positions. This will become tedious. For Record collection, locality of reference and Ideal Cache behaviour we can use parallel arrays.
Q: Which of the following is an advantage of parallel arrays?
A. Poor locality of reference for non-sequential access
B. Very little direct language support
C. Expensive to shrink or grow
D. Increased Locality of Reference
Solution: Elements in the parallel array are accessed sequentially as one arrays holds the keys whereas other holds the values. This sequential access generally improves Locality of Reference. It is an advantage.
Q: What is a sorted array?
A. Arrays sorted in numerical order
B. Arrays sorted in alphabetical order
C. Elements of the array are placed at equally spaced addresses in the memory
D. All of the mentioned
Solution: The array can be sorted in any way, numerical, alphabetical or any other way but the elements are placed at equally spaced addresses.

You Have Score    /9